package org.example.modules.user.controller;

import org.example.modules.user.common.Commsult;
import org.example.modules.user.entry.Chat;
import org.example.modules.user.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description ChatController
 * @Author xiaotian
 * @Date 2025-04-20
 */
@RestController
@RequestMapping("/wxApi/chat")
public class ChatController {

    @Autowired
    private ChatService chatService;

    // 发送消息
    @PostMapping("/send")
    public Commsult<Chat> sendMessage(@RequestBody Chat chat) {
        return Commsult.success(chatService.sendMessage(chat));
    }

    // 获取聊天记录
    @GetMapping("/messages/{senderId}/{receiverId}/{jobId}")
    public Commsult<List<Chat>> getMessages(
            @PathVariable String senderId,
            @PathVariable String receiverId,
            @PathVariable String jobId) {
        return Commsult.success(chatService.getMessages(senderId, receiverId,Integer.valueOf(jobId)));
    }
    @GetMapping("/byOrderId/{orderId}")
    public Commsult<List<Chat>> getMessagesByOrderId(
            @PathVariable String orderId) {
        return Commsult.success(chatService.getMessagesByOrderId(Integer.valueOf(orderId)));
    }
}